# apps/monitoring/serializers.py

from rest_framework import serializers
from .models import SensorReading, ActionLog

class SensorReadingSerializer(serializers.ModelSerializer):
    room_id   = serializers.IntegerField(source='room.room_id', read_only=True)
    room_name = serializers.CharField(source='room.name',      read_only=True)

    class Meta:
        model  = SensorReading
        fields = ('reading_id','room_id','room_name',
                  'temperature','humidity','recorded_at')

class ActionLogSerializer(serializers.ModelSerializer):
    user_name   = serializers.CharField(source='user.username',          read_only=True)
    device_name = serializers.CharField(source='device.device_name',     read_only=True)
    room_name   = serializers.CharField(source='device.room.name',       read_only=True)

    class Meta:
        model  = ActionLog
        fields = ('log_id','user_name','device_name','room_name',
                  'action_type','old_value','new_value','timestamp')
